﻿@model asMeishi.web.Models.food
@using asMeishi.web.Models
@using asMeishi.web.Classes
@using publicLibrary;
@{
    Layout = null;

    ViewBag.Title = "p_items_detail";
    IQueryable<history> hs = ViewBag.history as IQueryable<history>;
    var impus = ViewBag.impressUser;
}


<div class="foodDetailPanel" id="foodPanel" foodId="@Model.Id">
    <span style=" float:right">(创建人:@@<A href="">@Model.getUserName()</A><span class="datetime">@Model.datatime</span>)</span>
            <div class="title" style="margin:5px 0px;">
                <span style="font-size:26px;" id="foodName" revise="true" inputValue="@Model.name">@Model.name</span> | 价格：<span id="foodPrice" revise="true" inputValue="@Model.price">@Model.price</span>元
            </div>
            <div class="intro" style=" padding:4px 10px; color:Gray" id="foodIntro" revise="true" inputValue="@Model.intro">
                @Model.intro
            </div>
            <div>
                <span class="tag2 handle" title="推荐">@(Model.recommendCount)</span>
                <span class="tag2 comm" title="点评">@Model.commentsCount</span>
            </div>
            <div style=" margin:10px;">
                <span class="hand" style="vertical-align:top"><img src="/Content/themes/metro/images/picture_add.png" onclick="showfoodPicUpload('@Model.Id')" alt="上传图片" title="上传图片" /></span>
                @Model.picUrls.SplitToHTMLbyCode("<a href='/upload/foodPic/_var_' rel='lightbox[foodPic]'><img src='/upload/foodPic/s/_var_.jpg' height='40' class='foodPicItem'  /></a>")
            </div>



            <form class="impressForm" id="impressForm" >
                <div style=" height:42px; width:100px; float:left">
                    <div style=" text-align:center">吃货点评：</div>
                    <div id="starRate"></div>
                    
                </div>
                <textarea  id="impressContent"  name="content" style=" height:38px"></textarea>
                <button onclick="addItemImpress()" class="btn btn-yellow" style=" height:42px; vertical-align:top;">提交</button>
                <input type="hidden" id="foodGrade" name="foodGrade" value="0" />
                <input type="hidden" id="itemId" name="itemId" value="@Model.Id" />
                <input type="hidden" id="loginUserId" value="@userC.loginUser.Id" />
                <input type="hidden" id="loginUserName" value="@userC.loginUser.name" />
            </form>

            <div class="impressList" id="itemImpressList" onclick="actionItemImpress(event)">
                @foreach (var impu in impus)
                {
                    impression imp = impu[0];
                    user user = impu[1];
                    <div class="impress">
                        <span class="datetime">@imp.datetime.ToLongDateString()</span>
                        @if (powerCheck.recordEditDel(imp.userId.ToString(), userC.loginUser))
                        {                  
                            <button class="delBtn" targetId="@imp.Id.ToString()">del</button>
                        }
                        <a href="@imp.userId" class="authorLink">@@@user.name</a>点评 (@imp.grade):<div class="content">@imp.content</div> 
                        

                    </div>
                }
            </div>
</div>
<script>
    $(function () {
        $('#starRate').Rate({
            fun: function (rate) {
                $("#foodGrade").val(rate);
            }
        });

    })
    function actionItemImpress(evt) {
        var el = $.event.fix(event).target;
        if (el.className == ("delBtn")) {
            alert(el.getAttribute("targetId"))
            $.get("/item/delImpression/" + $("#itemId").attr("value"), { impressId: el.getAttribute("targetId") }, function (str) {
                alert(str.result)
            })
        }
    }
    function addItemImpress() {
        var _content = document.getElementById("impressContent").value;
        if (_content == "") { alert("不能为空"); return; }

        $.post("/food/addImpression/" + $("#itemId").attr("value"), $("#impressForm").serialize(), function (result) {
            inserImpress(result)
        });
    }
    function inserImpress(json) {
        json = eval(json)
        alert(json.content)
        if (json.result == "ok") {
            $("#itemImpressList").prepend('<div class="impress"><span class="datetime">' + (new Date()).pattern("yyyy-MM-dd") + '</span><button class="delBtn" targetId="' + json.content + '">del</button><a href="' + $("#loginUserId").val() + '" class="authorLink">' + $("#loginUserName").val() + '</a><div class="content">' + $("#impressContent").val() + '</div></div>')
        }
    }
</script>